package br.unifor.cct.mia.mutation;

import br.unifor.cct.mia.dataenhancement.Structure;
import br.unifor.cct.mia.evolutionary.HugeScaleGenotype;
import br.unifor.cct.mia.ga.Ga;
import br.unifor.cct.mia.ga.util.HugeScaleGene;
import br.unifor.cct.mia.util.Methods;

public class HugeScaleMutation implements Mutation {

	private void mutate(Ga ga, Structure struc) {
		double x;

		for (int i = 0; i < ga.configurations.getPopsize(); i++) {

			x = Methods.randDoubleValue(0, 1);

			if (x*100 < ga.configurations.getPmutation()*100) {				 

				int j = Methods.randIntValue(0, ga.configurations.getNvars()-1);
				int pos = Methods.randIntValue(0, 1);

				HugeScaleGenotype indiv = (HugeScaleGenotype) ga.population[i];
				HugeScaleGene gen = indiv.getGene()[j];

				gen.getBits()[pos] = Methods.randIntValue(0, 1);				
			}

		}
	}

	public Object execute(Object value) {
		Object[] o = (Object[])value;
		Structure struc = (Structure)o[0];
		Ga Ga = (Ga)o[1];

		mutate(Ga,struc);        
		return Ga.population;
	}

}
